<!--
 * @Author: your name
 * @Date: 2021-07-10 19:37:25
 * @LastEditTime: 2021-07-10 19:56:21
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \vue-hr-project\src\test\一个函数将对象数组处理成二维数组.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>实现一个函数将对象数组处理成二维数组</h1>

    <script>
        let sourceData = [
            { name: "张三", age: 18 }, { name: "李四", age: 28 }, { name: "王五", age: 38 }
        ]

        let targetData = [
            ['张三', 18],
            ['李四', 28],
            ['王五', 38]
        ]

        function transData(sourceData) {
            let newArr = []
            // 逻辑处理
            sourceData.forEach((item) => {
                // newArr.push(item)
                // { name: "张三", age: 18 }
                // { name: "李四", age: 28 }
                // { name: "王五", age: 38 }
                newArr.splice(0,0,[item.name,item.age])
                // 0: (2)["王五", 38]
                // 1: (2)["李四", 28]
                // 2: (2)["张三", 18]
            })

            return newArr
        }
        const res = transData(sourceData)
        console.log(res);

        
    </script>
</body>

</html>